// Bring out your Dead - White Wolf character Management System.
// Copyright (C) 2008 Adam Ness
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Boyd.Model;
using Boyd.Controller;

namespace Boyd.View
{
	/// <summary>
	/// Description of AttributePanel.
	/// </summary>
	public partial class AttributePanel : UserControl
	{
		private Character character;
		private IController controller;

		public AttributePanel() {
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
		}
		
		public AttributePanel( IController controller )
		{
			this.controller = controller;
		}
		
		public Character Character{
			get { return character; }
			set { character = value; updateCharacterValues(); }
		}
		
		private void updateCharacterValues() {
			if( Character == null ) {
				inputIntelligence.Text = "";
				inputWits.Text = "";
				inputResolve.Text = "";
				inputStrength.Text = "";
				inputDexterity.Text = "";
				inputStamina.Text = "";
				inputPresence.Text = "";
				inputManipulation.Text = "";
				inputComposure.Text = "";
			} else {
				inputIntelligence.Text = Character.Intelligence.Rating.ToString();
				inputWits.Text = Character.Wits.Rating.ToString();
				inputResolve.Text = Character.Resolve.Rating.ToString();
				inputStrength.Text = Character.Strength.Rating.ToString();
				inputDexterity.Text = Character.Dexterity.Rating.ToString();
				inputStamina.Text = Character.Stamina.Rating.ToString();
				inputPresence.Text = Character.Presence.Rating.ToString();
				inputManipulation.Text = Character.Manipulation.Rating.ToString();
				inputComposure.Text = Character.Composure.Rating.ToString();
			}
		
		}
		
		void ValueChanged(object sender, EventArgs e)
		{
			NumericUpDown nudSender = (NumericUpDown)sender;
			CharacterAttributeUpdateCommand command = new CharacterAttributeUpdateCommand();
			command.Character = Character;
			command.AttributeName = nudSender.Name.Remove(0,5);
			command.NewRating = (int)nudSender.Value;
			controller.QueueCommand(command);
		}
	}
}
